package File_IO;

import java.io.*;

public class homework01 {

    public static void main(String[] args) {
        //写出过程
        FileOutputStream fos = null;
        String str = "HelloWorld.";
        byte[]words = str.getBytes();
        try {
            fos = new FileOutputStream("D:\\test.txt",true);
            try {
                fos.write(words,0,words.length);
                System.out.println("test已经更新");
            } catch (IOException e) {
                System.err.println("test更新失败");
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            if (fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }



        //读入
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("D:\\test.txt");
            int data=fis.read();
            System.out.println("test的内容为");
            while (data!=-1){
                System.out.print((char)data);
                data=fis.read();
            }
        }catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(fis!=null){
                    fis.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }


    }

}
